package ru.tennisworld.user.mappers;

import org.mapstruct.Mapper;
import org.mapstruct.Named;
import org.springframework.beans.factory.annotation.Autowired;
import ru.tennisworld.user.config.MapstructConfig;
import ru.tennisworld.user.utils.EncryptionUtils;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

@Mapper(config = MapstructConfig.class)
public abstract class EncryptMapper {

    @Named("encryptStringData")
    public String encryptString(String data) throws NoSuchPaddingException, IllegalBlockSizeException,
            NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
        return EncryptionUtils.encryptStringValue(data);
    }

    @Named("encryptLongData")
    public String encryptLong(Long data) throws NoSuchPaddingException, IllegalBlockSizeException,
            NoSuchAlgorithmException, BadPaddingException, InvalidKeyException {
        return EncryptionUtils.encryptStringValue(data.toString());
    }
}
